﻿Public Class FrmAddScrew
    Private Sub Button_Complete_Click(sender As Object, e As EventArgs) Handles Button_Complete.Click
        Try
            OPC_Machine_AddScrew.AddScrewCount_Feeder1 = Val(TextBox_Count1.Text)
            OPC_Machine_AddScrew.AddScrewCount_Feeder2 = Val(TextBox_Count2.Text)
            OPC_Machine_AddScrew.AddScrew_Complete = 1
            OPC_AddScrewRemind = False
            OPC_Machine_AddScrew.AddScrew_Remind = 0
            FrmMain.OPC_Refresh_AddScrew()
            OPC_Machine_AddScrew.AddScrew_Complete = 0
            OPC_Machine_AddScrew.AddScrewCount_Feeder1 = 0
            OPC_Machine_AddScrew.AddScrewCount_Feeder2 = 0
            MsgBox("加螺丝完成")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub Button_Add1_Click(sender As Object, e As EventArgs) Handles Button_Add1.Click
        Try
            OPC_Machine_AddScrew.Clear_Feeder1 = 1
            OPC_Machine_AddScrew.AddScrewCount_Feeder1 = 0
            SaveSetting("XCPro", "Settings", "ScrewCountFeeder1", OPC_Machine_AddScrew.AddScrewCount_Feeder1)

            FrmMain.OPC_Refresh_AddScrew()
            OPC_Machine_AddScrew.Clear_Feeder1 = 0
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub Button_Add2_Click(sender As Object, e As EventArgs) Handles Button_Add2.Click
        Try
            OPC_Machine_AddScrew.Clear_Feeder2 = 1
            OPC_Machine_AddScrew.AddScrewCount_Feeder2 = 0
            SaveSetting("XCPro", "Settings", "ScrewCountFeeder2", OPC_Machine_AddScrew.AddScrewCount_Feeder2)

            FrmMain.OPC_Refresh_AddScrew()
            OPC_Machine_AddScrew.Clear_Feeder2 = 0
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub FrmAddScrew_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            TextBox_Count1.Text = OPC_Machine_AddScrew.AddScrewCount_Feeder1
            TextBox_Count2.Text = OPC_Machine_AddScrew.AddScrewCount_Feeder2

            TextBox_lastCount1.Text = OPC_Machine_AddScrew.LastCount_Feeder1
            TextBox_lastCount2.Text = OPC_Machine_AddScrew.LastCount_Feeder2

            TextBox_Lockcount1.Text = OPC_Machine_AddScrew.LockCount_Feeder1
            TextBox_Lockcount2.Text = OPC_Machine_AddScrew.LockCount_Feeder2

            Timer1.Enabled = True
        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Sub

    Private Sub FrmAddScrew_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        Try
            Timer1.Enabled = False
            FrmMain.OPC_Refresh_AddScrew()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Try
            TextBox_lastCount1.Text = OPC_Machine_AddScrew.LastCount_Feeder1
            TextBox_lastCount2.Text = OPC_Machine_AddScrew.LastCount_Feeder2
        Catch ex As Exception

        End Try
    End Sub
End Class